package com.wbao.dianniu.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.ActivityInfos;
import com.wbao.dianniu.utils.PictureDownloadUtils;

/**
 * 加入活动用户列表
 * 
 * @author yejianjun
 * 
 */
public class JoinActAccountAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<ActivityInfos> mList;
	private Context mContext;

	public JoinActAccountAdapter(Context context) {
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mContext = context;
	}

	public void setData(List<ActivityInfos> list) {
		mList = list;
	}

	public List<ActivityInfos> getList() {
		return mList;
	}

	@Override
	public int getCount() {
		if (null == mList)
			return 0;
		else
			return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GridHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.join_act_account_list_item, null);
			holder = new GridHolder();
			holder.headIV = (ImageView) convertView.findViewById(R.id.join_act_headpic);
			holder.nameTV = (TextView) convertView.findViewById(R.id.join_act_name);
			holder.labelTV = (TextView) convertView.findViewById(R.id.join_act_label);
			convertView.setTag(holder);
		} else {
			holder = (GridHolder) convertView.getTag();
		}
		ActivityInfos data = mList.get(position);
		if (null != data) {
			PictureDownloadUtils.displayHeadImage(mContext,holder.headIV, data.headPic);
			holder.nameTV.setText(data.realName == null ? "" : ""	+ data.realName);
			holder.labelTV.setText(data.label == null ? "" : "" + data.label);
		}
		return convertView;
	}

	private class GridHolder {
		public ImageView headIV;
		public TextView nameTV;
		public TextView labelTV;
	}

}
